app.controller('foundEamicCtrl', ['$scope', '$rootScope', '$filter', 'pcdService', 'listSve', '$http', function($scope, $rootScope, $filter, pcdService, listSve, $http) {
	$rootScope.navIndex = 5;
	//获取省列表
	$scope.getPro = function() {
		pcdService.prolist().list().then(function(e) {
			$scope.prolist = e.data;
		})
		pcdService.citylist().list().then(function(e) {
			$scope.oCityList = e.data;
		})
		pcdService.dislist().list().then(function(e) {
			$scope.oDisList = e.data;
		})
	}
	$scope.getPro();
	$scope.pageInx = {}
	var pagerBox = document.getElementById('pager_1');
	//列表
	$scope.getItem = function() {
		listSve.cList().list({
			numPerPage: 10
		}).then(function(e) {
			console.info(e);
			$scope.list_1 = e.res.data;
			var count = Math.ceil(e.res.page.recordCount / 10);
			$scope.count = count;
			var pager = new Pager({
				index: 1,
				total: $scope.count,
				parent: pagerBox,
				onchange: doChangePage
			});
		});

	}
	$scope.first = true;
	$scope.getItem();
	//分页器
	function doChangePage(obj) {
		if($scope.first) {
			$scope.first = false;
		} else {
			console.info(obj.index)
			$scope.pageInx = {
				pageNum: obj.index,
				numPerPage: 10
			};
			//				$scope.getItem();
			listSve.cList().list($scope.pageInx).then(function(e) {
				console.info(e);
				if(flag == "a") { //在全选的基础上操作
					$scope.master = false;// 还原设置
				}
				$scope.choseArr = '';
//				$scope.oDB = true;
//				$scope.oMS = true;
				$scope.list_1 = e.res.data;

			})
		}
	}

	//省市区联动
	$scope.proFunc_1 = function(e) {
		console.info(e)
		var proId = e;
		//e.data
		$scope.citylist = new Array;
		$scope.cty_1 = '';
		$scope.dis_1 = '';
		$scope.dislist = '';
		for(var i = 0; i < $scope.oCityList.length; i++) {
			if($scope.oCityList[i].pro_id == proId) {
				$scope.citylist.push($scope.oCityList[i]);
			}
		}

	}
	$scope.ctyFunc_1 = function(e) {
			var ctyId = e;
			//e.data
			$scope.dislist = new Array;
			$scope.dis_1 = '';
			for(var i = 0; i < $scope.oDisList.length; i++) {
				if($scope.oDisList[i].city_id == ctyId) {
					$scope.dislist.push($scope.oDisList[i]);
				}
			}
		}

	$scope.newSearch = function(ele){
		console.info(ele)
	}
	//搜索
	$scope.oDB = true;
	$scope.oMS = true;
	$scope.sear_2 = function(way, pro, cty, dis, tric_nmb, adr_nmb, floor_nmb, unit_nmb, room_nmb, db, ms) {
		//判断是否点击条件显示按钮
		if (db) {
			$scope.oDB = false;
		}else {
			$scope.oDB = true;
		};
		if (ms) {
			$scope.oMS = false;
		}else{
			$scope.oMS = true;
		};
		
		//	 	console.info(JSON.parse(pro).pro_id)
		//	 	console.info(way+JSON.parse(pro).pro_id+JSON.parse(cty).city_id+JSON.parse(dis).dis_id);
//		$scope.first = true;
		$scope.first_2 = true;
		$scope.allSear = {};
		//$filter('proName')(h.houseStreet.provinceId, $scope.prolist) + $filter('cityName')(h.houseStreet.cityId, $scope.oCityList) + $filter('disName')(h.houseStreet.dist, $scope.oDisList) 
		$scope.allSear.provinceId = $filter('proName')(pro, $scope.prolist);
		$scope.allSear.cityId = $filter('cityName')(cty, $scope.oCityList);
		$scope.allSear.dist = $filter('disName')(dis, $scope.oDisList);
		$scope.allSear.type = way;

		//	 	$scope.allSear.cityId =JSON.parse(cty).city_id;
		//	 	$scope.allSear.dist =JSON.parse(dis).dis_id;
		$scope.allSear.street = adr_nmb;
		$scope.allSear.districtName = tric_nmb;
		$scope.allSear.unit = unit_nmb;
		$scope.allSear.floorNo = floor_nmb;
		$scope.allSear.roomNo = room_nmb;
		$scope.allSear.numPerPage = 10;
		//新增未安装门锁未安装电表搜索查询
		$scope.allSear.ammeterInstallStatus = db;
		$scope.allSear.doorLockInstallStatus = ms;
		console.info($scope.allSear)
		
		listSve.cList().list($scope.allSear).then(function(e) {
			console.info(e)
			if(flag == "a") { //在全选的基础上操作
					$scope.master = false;// 还原设置
				}
			$scope.choseArr = '';
			str = '';
			console.info($scope.choseArr)
			$scope.list_1 = e.res.data;
			var count = Math.ceil(e.res.page.recordCount / 10);
			$scope.count = count;
			pagerBox.innerHTML = "";
			var pager = new Pager({
				index: 1,
				total: $scope.count,
				parent: pagerBox,
				onchange: doChangePage_2
			});
		})
	}
	
	//搜索分页器
	function doChangePage_2(obj) {
		if($scope.first_2) {
			$scope.first_2 = false;
		} else {
			console.info(obj.index)
			$scope.allSear.pageNum = obj.index;
			//$scope.pageInx = {pageNum:obj.index,numPerPage:10,provinceId:9};
			//				$scope.getItem();
			listSve.cList().list($scope.allSear).then(function(e) {
				console.info(e);
				if(flag == "a") { //在全选的基础上操作
					$scope.master = false;// 还原设置
				}
				$scope.choseArr = '';
//				$scope.oDB = true;
//				$scope.oMS = true;
				$scope.list_1 = e.res.data;

			})
		}
	}
//全选系列操作
	$scope.choseArr = ''; // 定义数组用于存放前端显示
	
	var str = ""; //
	
	var flag = ""; // 是否点击了全选，是为a
	
	$scope.isSelect = false; // 默认未选中
	
	$scope.checkAll = function(c, v) { // 全选
		str = "";
		if(c == true) {
			$scope.isSelect = true;
			for (i=0;i<v.length;i++) {
//				$scope.choseArr.push(v[i].id);
				str = str + v[i].id + ",";
			}
			$scope.choseArr = str;
		} else {
			$scope.isSelect = false;
			$scope.choseArr = '';
			str = "";
		}
		flag = "a";
		console.info($scope.choseArr)
	};
	$scope.updateCheck = function(z, x) { //单选或者多选
		if(flag == "a") { //在全选的基础上操作
			str = $scope.choseArr + ",";
		}
		if(x == true) { //选中
			str = str + z + ",";
		} else {
			str = str.replace(z + ",", ""); //取消选中
		}
		$scope.choseArr = str.substr(0, str.length - 1);
//		$scope.choseArr = str;
		console.info($scope.choseArr)
	};


//点击创建门锁
	$scope.openDoorModal = function() {
		$scope.sMs = false;
	
		$('#modal_door').modal('show');
		listSve.supplierList().list({'type':'MENSUO'}).then(function(data) {
//			console.log(data);
			$scope.door_supplier_list = data.res.data;
		})

	}
//点击创建电表
	$scope.openAmmeterModal = function() {
		$scope.sDb = false;
		$('#modal_ammeter').modal('show');
		listSve.supplierList().list({'type':'DIANBIAO'}).then(function(data) {
//			console.log(data);
			$scope.ammeter_supplier_list = data.res.data;
		})

	}
	
	
	
//弹出选择门锁厂商
	$scope.createDoor = function(){
		$scope.sMs = true;
		var oDoorVal = angular.element("#doorSupplier").val();
			if(oDoorVal == '0' || $scope.choseArr.length == 0) {
				$scope.alert({
					show: true,
					Title: '系统提示',
					Message:'请完善信息',
					prevId: '',
					Type: false
				});
			}else{
//				$scope.oParmsM = {};
//				$scope.oParmsM.code = oDoorVal;
//				$scope.oParmsM.ids = $scope.choseArr;
//				console.info($scope.oParmsM)
				//提交
				$('#loading').modal('show');
				listSve.setupDoor().delete({code:oDoorVal,orderId:$scope.choseArr}).then(function(data){
					console.log(data);
					if (data.code == 0) {
						$('#loading').modal('hide');
						$scope.alert({
							show: true,
							Title: '系统提示',
							Message:'创建成功！',
							prevId: '',
							Type: true
						});
						$scope.calback = function(){
							$('#modal_door').modal('hide');
						};
					} else{
						$('#loading').modal('hide');
						$scope.alert({
							show: true,
							Title: '系统提示',
							Message:data.res.msg,
							prevId: '',
							Type: true
						});
						
					}
				})
				
				
			}
		
		
		
	}

//弹出选择电表厂商
	$scope.createAmmeter = function(){
		$scope.sDb = true;
		var oAmmeterVal = angular.element("#ammeterSupplier").val();
			if(oAmmeterVal == '0' || $scope.choseArr.length == 0) {
				$scope.alert({
					show: true,
					Title: '系统提示',
					Message:'请完善信息',
					prevId: '',
					Type: false
				});
			}else{
//				$scope.oParms = {};
//				$scope.oParms.code = oAmmeterVal;
//				$scope.oParms.ids = $scope.choseArr;
//				console.info($scope.oParms)
				//提交
				$('#loading').modal('show');
				listSve.setupAmmeter().delete({code:oAmmeterVal,orderId:$scope.choseArr}).then(function(data){
					console.log(data);
					if (data.code == 0) {
						$('#loading').modal('hide');
						$scope.alert({
							show: true,
							Title: '系统提示',
							Message:'创建成功！',
							prevId: '',
							Type: true
						});
						$scope.calback = function(){
							$('#modal_ammeter').modal('hide');
						};
					} else{
						$('#loading').modal('hide');
						$scope.alert({
							show: true,
							Title: '系统提示',
							Message:data.res.msg,
							prevId: '',
							Type: true
						});
						
					}
				})
				
				
			}
	}








}])